const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchfocus: false,
    animationData: "",
    left: "200rpx",
    page: 1,
    orderList: [],
    key: ''
  },
  onFocus: function () {
    console.log("111");
    var that = this;
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'ease',
    })
    that.animation = animation
    animation.left("650rpx").step();
    that.setData({
      animationData: animation.export(),
      searchfocus: true
    })
  },
  onBlur: function () {
    this.setData({
      left: "200rpx",
      searchfocus: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getOrderList(1)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.setData({
      orderList: []
    });
    this.getOrderList(1);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.getOrderList(this.data.page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  /**
   * 获取订单列表
   */
  getOrderList(page) {
    var that = this;
    wx.request({
      url: app.globalData.server + "/merchantApplet/merchantFindOrder",
      data: {
        page: page,
        orgId: wx.getStorageSync('orgId'),
        key: that.data.key
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function(res) {
        console.log(res.data);
        if (res.data.code != '000000') {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 1000
          })
        } else {
          var oldOrderList = that.data.orderList;
          oldOrderList = oldOrderList.concat(res.data.data);
          that.setData({
            orderList: oldOrderList,
            page: that.data.page + 1
          });
          wx.stopPullDownRefresh(); //停止下拉刷新
        }
      }
    })
  },
  /**
   * 点击进行搜索
   */
  search:function(){
    console.log("进行搜索");
  }
})